<?php

namespace Modules\Admin\Http\Controllers;

use Illuminate\Support\Facades\Request;
use Modules\Admin\Service\NoticeService;
use Modules\Admin\Http\Requests\notice\NoticeRequest;


class NoticeController extends BaseController
{

    private $notice_types = ['1'=>'小程序','2'=>'安卓','3'=>'ios','4'=>'公众号','5'=>'后台'];

    /**
     *  公告列表
     *  hinq 2019 08 21
     *
     **/
    public function index(){
        $arr_search = (array)Request::input();
        $arr_list = NoticeService::get_list( (array) $arr_search );
        echo_error($arr_list);
        return view('admin::notice.index',$arr_list['data']);
    }

    /**
     *  添加公告视图
     *  hinq 2019 08 21
     *
     **/
    public function create(){
        return view('admin::notice.create',['arr'=>$this->notice_types] );
    }

    /**
     *  添加公告到数据库
     *  hinq 2019 08 21
     *
     **/
    public function store( NoticeRequest $request){
        $arrInput = (array)Request::all();
        return NoticeService::addOne( (array) $arrInput);
    }



    /**
     *  编辑公告视图
     *  hinq 2019 08 21
     *
     **/
    public function edit(){
        $id = (int)Request::get('id',0);
        $arr_info = NoticeService::getOne( (int) $id );
        return view('admin::notice.edit',['info' => $arr_info , 'arr' => $this->notice_types ]);
    }


    /**
     *  编辑公告数据
     *  hinq 2019 08 21
     *
     **/
    public function update(){
        $arrInput = (array) Request::all();
        return NoticeService::edit_one( (array) $arrInput );
        
    }


    /**
     *  删除公告
     *  hinq 2019 09 10
     *
     **/
    public function del(){
        $nId = (int) Request::get('id',0);
        return NoticeService::del_one( (int) $nId );
    }


}